/**
 * Created by zby on 2018/3/25.
 */
public class Test3_4_3 {
    public static void main(String[] args) {
        System.out.println("用do-while语句计算1+1/2！+1/3！+……+1/20！");
        double sum = 0, item = 1;
        int i = 1, n = 20;
        do {
            sum = sum + item;
            i++;
            item = item * (1.0 / i);
        } while (i <= n);
        System.out.println("sum=" + sum);
        System.out.println("用for语句计算1+1/2！+1/3！+……+1/20！");
        double s = 0;
        double it = 1;
        for (int j = 1; j <= 20; j++) {
            s = s + it;
            it = it * (1.0 / (j + 1));
        }
        System.out.println("sum=" + s);
    }
}
